#include "head.h"

int initSocket(int *socketfd){
    *socketfd = socket(AF_INET,SOCK_STREAM,0);
    ERROR_CHECK(*socketfd,-1,"socketfd");

    char *ip = "192.168.75.128";
    char *port = "8080";

     // 解除TIME_WAIT等待时:导致端口占用问题
    int reuse = 1;
    setsockopt(*socketfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
    struct sockaddr_in sockadd;
    sockadd.sin_family= AF_INET;
    sockadd.sin_port=htons(atoi(port));
    sockadd.sin_addr.s_addr = inet_addr(ip);
    
    int ret_bind=bind(*socketfd,(struct sockaddr*)&sockadd,sizeof(sockadd));
    ERROR_CHECK(ret_bind,-1,"ret_bind");

    listen(*socketfd,10);
    
    return 1;
}



